// pages/settings/settings.js
const app = getApp();
var WebIM = require('../../utils/WebIM.js');
var WebIM = WebIM.default;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    operation: [
      {
        operate: '修改手机号码',
        url: '../changePhone/CheckOldPhone'
      },
      {
        operate: '用户反馈',
        url: '../feedback/feedback'
      },
      {
        operate: '修改权限'
      }
    ],
    userStatus: false
  },
  /**
   * 跳转到下一个页面
   */
  toItemNextPage: function (e) {
    // console.log(e.currentTarget.id);
    let that = this;
    if (e.currentTarget.id == 2) {
      wx.openSetting({
        success: (res) => {
          if (res.authSetting["scope.userInfo"]) {
            app.login();
          }
          if (res.authSetting["scope.userLocation"]) {
            app.setMyLocation();
            app.globalData.isNewIndex = true;
            app.globalData.isNewNearBy = true;
          }
        }
      })
      return;
    }
    let currentUrl = this.data.operation[e.currentTarget.id].url;
    wx.navigateTo({
      url: currentUrl
    })
  },
  /**
   * 退出登录
   */
  exitState: function () {
    wx.setStorageSync("sessionId", '');
    wx.setStorageSync('userInfo', '')
    WebIM.conn.close();
    wx.showToast({
      title: '您已经成功退出登录',
      icon: 'none',
      duration: 1500
    });
    setTimeout(() => {
      wx.reLaunch({
        url: '../index/index'
      })
    }, 1500);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let userStatus = app.isPhoneLogin();
    this.setData({
      userStatus: userStatus
    })
  },
})